package com.example.leetdemo.finash;

public class Solution80 {

    public int removeDuplicates(int[] nums) {
        int p = 0, q = 0;
        for (int i = 1; i < nums.length; i++) {
            if (p == q) {
                q++;
                nums[q] = nums[i];
            } else {
                if (nums[i] != nums[q]){
                    q++; p = q;
                    nums[q] = nums[i];
                } else if (nums[i] == nums[q] && nums[i] != nums[p]) {
                    p = q; q++;
                    nums[q] = nums[i];
                }
            }
        }
        return q + 1;
    }

    public static void main(String[] args) {
        Solution80 solution80 = new Solution80();
        System.err.println(solution80.removeDuplicates(new int[] {0,0,1,1,1,1,2,3,3}));
    }

}
